package com.jzo2o.customer.service.impl;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.jzo2o.api.customer.dto.response.CommonUserResDTO;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.mapper.WorkerCertificationAuditMapper;
import com.jzo2o.customer.model.domain.CommonUser;
import com.jzo2o.customer.model.domain.WorkerCertificationAudit;
import com.jzo2o.customer.model.dto.request.WorkerCertificationAuditPageQueryReqDTO;
import com.jzo2o.customer.model.dto.response.WorkerCertificationAuditResDTO;
import com.jzo2o.customer.service.WorkerCertificationAuditService;
import com.jzo2o.mysql.utils.PageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【worker_certification_audit(服务人员认证审核表)】的数据库操作Service实现
* @createDate 2024-08-19 22:24:46
*/
@Service
public class WorkerCertificationAuditServiceImpl extends ServiceImpl<WorkerCertificationAuditMapper, WorkerCertificationAudit>
    implements WorkerCertificationAuditService {

    @Autowired
    protected WorkerCertificationAuditMapper workerCertificationAuditMapper;

    @Override
    public PageResult<WorkerCertificationAudit> selectPage(WorkerCertificationAuditPageQueryReqDTO pageQueryReqDTO) {
        //1.分页查询用户
        Page<WorkerCertificationAudit> page = PageUtils.parsePageQuery(pageQueryReqDTO, WorkerCertificationAudit.class);

        QueryWrapper<WorkerCertificationAudit> workerCertificationAuditQueryWrapper = new QueryWrapper<>();

        //审核状态不为空,加入审核状态条件
        if (ObjectUtil.isNotNull(pageQueryReqDTO.getAuditStatus())) {
            workerCertificationAuditQueryWrapper.lambda().eq(WorkerCertificationAudit::getAuditStatus, pageQueryReqDTO.getAuditStatus());
        }
        //认证状态不为空,加入认证状态条件
        if (ObjectUtil.isNotNull(pageQueryReqDTO.getCertificationStatus())) {
            workerCertificationAuditQueryWrapper.lambda().eq(WorkerCertificationAudit::getCertificationStatus, pageQueryReqDTO.getCertificationStatus());
        }
        //身份证不为空,加入身份证条件
        if (ObjectUtil.isNotEmpty(pageQueryReqDTO.getIdCardNo())) {
            workerCertificationAuditQueryWrapper.lambda().eq(WorkerCertificationAudit::getIdCardNo, pageQueryReqDTO.getIdCardNo());
        }
        //姓名不为空,加入姓名条件
        if (ObjectUtil.isNotEmpty(pageQueryReqDTO.getName())) {
            workerCertificationAuditQueryWrapper.lambda().eq(WorkerCertificationAudit::getName, pageQueryReqDTO.getName());
        }



        Page<WorkerCertificationAudit> workerCertificationAuditPage = workerCertificationAuditMapper.selectPage(page, workerCertificationAuditQueryWrapper);

        //3.封装数据
        return PageUtils.toPage(workerCertificationAuditPage, WorkerCertificationAudit.class);
    }

    @Override
    public WorkerCertificationAuditResDTO rejectReason(Long id) {
        //根据ID查询认证信息
        WorkerCertificationAudit workerCertificationAudit = this.getById(id);
        if (ObjectUtil.isNull(workerCertificationAudit)) {
            throw new RuntimeException("认证信息不存在");
        }
        WorkerCertificationAuditResDTO workerCertificationAuditResDTO = BeanUtil.toBean(workerCertificationAudit, WorkerCertificationAuditResDTO.class);
        return workerCertificationAuditResDTO;
    }
}




